/*
	The player's account file is automatically created when they join.
	The file's name is the player's steam id without the _'s or :'s.
	It contains various info like: points, playermodel preferences, and unlocks.
	Information can be added to the end of the file and it will not effect anything else.
*/

--This function opens the file containing all of the specified player's settings and unlocks and returns a table containing all of that info
function Get_Player_Data( pl )
	if (string.find(pl:Nick(), "Bot") == nil and pl:SteamID() != "BOT") then
		pl_data = ""
		filename = 	string.gsub( string.gsub( pl:SteamID( ), ":", "" ), "_", "" ) .. ".txt"
		if ( file.Exists( "Dodgeball/players/"  .. filename ) ) then
			--Load all of the players info and put it into a table
			pl_data = file.Read( "Dodgeball/players/" .. filename )
		else
			--Create a new file and put some default settings into that file.
			pl_data = pl:Nick( ) .. "\n0\n" .. table.Random( PlayerModelsCombine ) .. "\n" .. table.Random( PlayerModelsLambda ) .. "\nDefault"
			file.Write( "Dodgeball/players/" .. filename, pl_data )
		end
		data = string.Explode( "\n", pl_data )
		return data
	end
end


--This function saves all of the player's information into the player's data file (named by the player's steam ID)
function Save_Player_Data( pl )
	if (string.find(pl:Nick(), "Bot") == nil and pl:SteamID() != "BOT") then
		print( "Saving " .. pl:Nick( ) .. "'s information." )
		filename = pl:SteamID( )
		filename = 	string.gsub( string.gsub( pl:SteamID( ), ":", "" ), "_", "" ) .. ".txt"
		total_playtime = pl.TimeSoFar + ( CurTime( ) - pl.JoinTime )
		pl_data = pl:Nick( ) .. "\n" .. tostring( total_playtime ) .."\n" .. pl.PrefCombModel .. "\n" .. pl.PrefLambModel .. "\n"
		file.Write( "Dodgeball/players/" .. filename, pl_data )
	end
end